#! /bin/bash

DATAX_HOME=/opt/module/datax

#DataX导出路径不允许存在空文件，该函数作用为清理空文件
handle_export_path(){
  for i in `hadoop fs -ls -R $1 | awk '{print $8}'`; do
    hadoop fs -test -z $i
    if [[ $? -eq 0 ]]; then
      echo "$i文件大小为0，正在删除"
      hadoop fs -rm -r -f $i
    fi
  done
}

#数据导出
export_data() {
  datax_config=$1
  export_dir=$2
  handle_export_path $export_dir
  $DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config
}

case $1 in
  "ads_traffic_stats_by_source_type")
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_source_type.json /warehouse/edu/ads/ads_traffic_stats_by_source_type
  ;;
   "ads_new_order_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
  ;;
  "ads_page_path")
    export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehousee/edu/ads/ads_page_path
  "ads_study_play_video_by_chapter")
    export_data /opt/module/datax/job/export/edu_report.ads_study_play_video_by_chapter.json /warehouse/edu/ads/ads_study_play_video_by_chapter
  ;;
  "ads_study_play_video_by_course")
    export_data /opt/module/datax/job/export/edu_report.ads_study_play_video_by_course.json /warehouse/edu/ads/ads_study_play_video_by_course
  ;;
  "ads_traffic_order_by_sc")
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_order_by_sc.json /warehouse/edu/ads/ads_traffic_order_by_sc
  "ads_audition_category_by_tm")
    export_data /opt/module/datax/job/export/edu_report.ads_audition_category_by_tm.json /warehouse/edu/ads/ads_audition_category_by_tm
  ;;  
  "ads_audition_subject_by_tm")
    export_data /opt/module/datax/job/export/edu_report.ads_audition_subject_by_tm.json /warehouse/edu/ads/ads_audition_subject_by_tm
  ;;
  "ads_audition_course_by_tm")
   export_data /opt/module/datax/job/export/edu_report.ads_audition_course_by_tm.json /warehouse/edu/ads/ads_audition_course_by_tm
  ;;
  "ads_new_order_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
  ;;
  "ads_new_pay_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_new_pay_user_stats.json /warehouse/edu/ads/ads_new_pay_user_stats
  ;;
  "ads_order_stats_by_cate")
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_cate.json /warehouse/edu/ads/ads_order_stats_by_cate
  ;;  
  "ads_order_stats_by_subject")
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_subject.json /warehouse/edu/ads/ads_order_stats_by_subject
  ;;
  "ads_order_stats_by_course")
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_course.json /warehouse/edu/ads/ads_order_stats_by_course
  ;;
  "ads_order_by_province")
    export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
  ;;
   "ads_finishclass_chapter_finish_amount")
    export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
  ;;
  "ads_user_change")
    export_data /opt/module/datax/job/export/edu_report.ads_finishclass_chapter_finish_amount.json /warehouse/edu/ads/ads_finishclass_chapter_finish_amount
  ;;  
  "ads_user_retention")
    export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
  ;;
  "ads_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
  ;;
  "ads_user_action")
    export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
  ;;
    "ads_new_order_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
  ;;
   "ads_ager_range_order_user")
    export_data /opt/module/datax/job/export/edu_report.ads_ager_range_order_user.json /warehouse/edu/ads/ads_ager_range_order_user
  ;;
  "all")
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_source_type.json /warehouse/edu/ads/ads_traffic_stats_by_source_type
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
    export_data /opt/module/datax/job/export/edu_report.ads_study_play_video_by_chapter.json /warehouse/edu/ads/ads_study_play_video_by_chapter
    export_data /opt/module/datax/job/export/edu_report.ads_study_play_video_by_course.json /warehouse/edu/ads/ads_study_play_video_by_course
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_order_by_sc.json /warehouse/edu/ads/ads_traffic_order_by_sc
    export_data /opt/module/datax/job/export/edu_report.ads_audition_category_by_tm.json /warehouse/edu/ads/ads_audition_category_by_tm
    export_data /opt/module/datax/job/export/edu_report.ads_audition_subject_by_tm.json /warehouse/edu/ads/ads_audition_subject_by_tm
    export_data /opt/module/datax/job/export/edu_report.ads_audition_course_by_tm.json /warehouse/edu/ads/ads_audition_course_by_tm
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_new_pay_user_stats.json /warehouse/edu/ads/ads_new_pay_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_cate.json /warehouse/edu/ads/ads_order_stats_by_cate
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_subject.json /warehouse/edu/ads/ads_order_stats_by_subject
    export_data /opt/module/datax/job/export/edu_report.ads_order_stats_by_course.json /warehouse/edu/ads/ads_order_stats_by_course
    export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
    export_data /opt/module/datax/job/export/edu_report.ads_finishclass_chapter_finish_amount.json /warehouse/edu/ads/ads_finishclass_chapter_finish_amount
    export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
    export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
    export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_ager_range_order_user.json /warehouse/edu/ads/ads_ager_range_order_user
  ;;
esac
